/*
 * Copyright 2007 Stefan Arentz <http://stefan.arentz.nl>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sateh.spaces.simple;

import com.sateh.spaces.SpaceConnection;
import com.sateh.spaces.SpaceConnectionFactory;
import com.sateh.spaces.SpaceException;

/**
 * 
 */

public class SimpleSpaceConnectionFactory implements SpaceConnectionFactory
{
    private final String url;

    public SimpleSpaceConnectionFactory(String url)
    {
        if (url == null) {
            throw new IllegalArgumentException("Argument 'url' cannot be null");
        }

        if (!url.startsWith("vm://")) {
            throw new IllegalArgumentException("Invalid argument 'url'");
        }

        this.url = url;
    }

    public SpaceConnection createConnection() throws SpaceException
    {        
        return new SimpleSpaceConnection(url.substring("vm://".length()));
    }
}
